package com.itheima.health.h5.controller;

import com.itheima.health.entity.QueryPageBean;
import com.itheima.health.entity.Result;
import com.itheima.health.pojo.CheckItem;
import com.itheima.health.service.CheckItemService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.dubbo.config.annotation.Reference;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.List;


@RestController
@Api(tags = "检查项模块管理")
public class CheckItemController {
    @Reference
    private CheckItemService checkItemService;
    //   开发 检查项模块   crud


    @GetMapping("checkitem/findAll")
    @ApiOperation(value = "查询检查项方法", notes = "查询所有的检查项列表信息")
    @PreAuthorize("hasAuthority('CHECKITEM_QUERY')")
    public Result findAll() {
        List<CheckItem> list = checkItemService.list();
        return new Result(list);
    }

    @PostMapping("checkitem/findPage")
    public Result findPage(@RequestBody QueryPageBean queryPageBean) {
        Result page = checkItemService.findPage(queryPageBean);
        return page;
    }

    @PostMapping("checkitem/add")
    public Result add(@RequestBody CheckItem checkItem) {
        Boolean flag = checkItemService.add(checkItem);

        return new Result(flag);
    }

    @DeleteMapping("checkitem/deleteCheckItemById/{id}")
    public Result deleteCheckItemById(@PathVariable("id") int id){
        Boolean flag = checkItemService.deleteCheckItemById(id);

        return new Result(flag);
    }

}

